package com.log.enhance.interceptor;

import com.log.enhance.constant.LogPluginConstant;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.slf4j.MDC;

/**
 * feign调用拦截器
 *
 * @author Mr_wenpan@163.com 2021/06/01 10:54
 */
public class FeignRequestInterceptor implements RequestInterceptor {
    /**
     * feign调用请求头中增加traceId，from 和 to
     *
     * @param requestTemplate requestTemplate
     * @author Mr_wenpan@163.com 2021/6/1 11:01 上午
     */
    @Override
    public void apply(RequestTemplate requestTemplate) {
        requestTemplate.header(LogPluginConstant.TRACEID, MDC.get(LogPluginConstant.TRACEID));
        requestTemplate.header(LogPluginConstant.FROM_WHICH_SERVICE, MDC.get(LogPluginConstant.TO_WHICH_SERVICE));
    }
}
